import { defineStore } from "pinia";
import { initAPI } from "@/config/storage/api";
import { initMP3ByID } from "@/config/storage/mp3ById";

export const useConfig = defineStore({
	id: "config",
	state: () => ({
		mp3ByID: true,
		customAPI: initAPI(),
		title: "音像资料自动编目系统",
		proxyAPI: window.location.host + "/api",
	}),
	actions: {
		setApi(api: string) {
			initAPI(api);
			this.customAPI = api;
		},

		setMp3ByID(state: boolean) {
			initMP3ByID(state);
			this.mp3ByID = state;
		},
	},
	getters: {
		API(state) {
			return import.meta.env.PROD ? state.customAPI : state.proxyAPI;
		},
	},
});
